--- title: Calibration Procedure keywords: fastai sidebar: home_sidebar summary: "Every OpenHSI camera is unique and requires calibration before use. This module provides the abstractions to create the calibration data which are then used in operation. " description: "Every OpenHSI camera is unique and requires calibration before use. This module provides the abstractions to create the calibration data which are then used in operation. " nb_path: "nbs/05_calibrate.ipynb" ---
There are two ways to create a SettingsBuilder class that words for your custom camera. (They involve Python metaclasses and mixins)
For example, you can then create a SettingsBuilder class that words for your custom camera by doing the following.
SettingsBuilder = create_settings_builder("SettingsBuilder",SimulatedCamera)
sb = SettingsBuilder(json_path="assets/cam_settings.json",pkl_path="assets/cam_calibration.pkl")
sb.update_intsphere_fit()
# other calibration functions...
sb.dump()
#hide_output
json_path='../cals/cam_settings_lucid_214302972.json'
pkl_path="../cals/openhsi_214302972.pkl"
SettingsBuilder = create_settings_builder("SettingsBuilder",LucidCamera)
#sb = SettingsBuilder(json_path="../assets/cam_settings.json",pkl_path="../assets/cam_calibration.pkl")
sb = SettingsBuilder(json_path=json_path,
pkl_path=pkl_path,
processing_lvl=-1,
pixel_format='Mono8',
# binxy=[2, 2],
# resolution=[540,720]
)
hvimg=sb.retake_flat_field(show=True)
hvimg.opts(width=800,height=800)
print(sb.calibration["flat_field_pic"].max())
hvimg
sb.update_row_minmax()
sb.update_resolution()
hvimg=sb.retake_HgAr(show=True)
hvimg.opts(width=800,height=800)
print(sb.calibration["HgAr_pic"].max())
hvimg
sb.update_smile_shifts()
sb.fit_HgAr_lines(top_k=10)
Each column in our camera frame (after smile correction) corresponds to a particular wavelength. The interpolation between column index and wavelength is slightly nonlinear which is to be expected from the diffraction grating - however it is linear to good approximation. Applying a linear interpolation gives an absolute error of $\pm$3 nm whereas the a cubic interpolation used here gives an absolute error of $\pm$ 0.3 nm (approximately the spacing between each column). Using higher order polynomials doesn't improve the error due to overfitting.
For fast real time processing, the fast binning procedure assumes a linear interpolation because the binning algorithm consists of a single broadcasted summation with no additional memory allocation overhead. A slower more accurate spectral binning procedure is also provided using the cubic interpolation described here and requires hundreds of temporary arrays to be allocated each time. Binning can also be done in post processing after collecting raw data.
fig = sb.update_intsphere_fit()
x = sb.update_intsphere_cube()